<style lang="less" scoped>
.course_container {
  width: 100%;
  margin-top: 60px;

  >header {
    width: 100%;
    height: 48px;
    padding: 0 32px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;

    >div:nth-child(1) {
      height: 48px;
      line-height: 48px;
      font-size: 36px;
      color: #333333;
      font-weight: 500;
      font-family: PingFangSC-Medium, PingFang SC;
      margin-bottom: 9px;
      z-index: 10;
    }

    >.course-more:nth-child(2) {
      height: 48px;
      line-height: 48px;
      display: flex;
      justify-content: center;
      align-items: center;

      span {
        font-size: 22px;
        color: #999999;
      }

      img {
        width: 16px;
        height: 16px;
        margin-left: 4px;
      }
    }

    >img {
      height: 19px;
      position: absolute;
      left: 32px;
      bottom: 0;
    }
  }

  .course-first-child {
    width: 100%;
    height: 148px;

    // background: #FFFFFF;
    // border-radius: 10px;
    // filter: blur(2px);
    .course-wrap-box {
      width: 685px;
      height: 148px;
      background: #FFFFFF;
      border-radius: 10px;
      margin: 30px auto 0;
      display: flex;
      justify-content: center;
      align-items: center;
      filter: drop-shadow(0 0 4px #E2E2E2);
      .left-img {
        width: 100px;
        height: 100px;
        border-radius: 6px;
        margin: 0 16px 0 24px;
      }

      .wrap-middle-box {
        flex: 1;

        .head {
          display: flex;
          // justify-content: center;
          align-items: center;
          margin-bottom: 7px;

          .icon {
            height: 24px;
            line-height: 24px;
            background: #5B76FF;
            color: #FFF;
            font-size: 16px;
            white-space: nowrap;
            border-radius: 4px;
            flex: none;
            padding: 0 4px;
            margin-right: 3px;
          }

          .title {
            width: 180px;
            font-size: 28px;
            color: #333333;
            font-weight: 700;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            margin-left: 4px;
            height: 30px;
            line-height: 30px;
          }
        }

        .sub_title {
          width: 350px;
          height: 28px;
          font-size: 20px;
          font-weight: 400;
          color: #999999;
          line-height: 28px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }

      .right-img {
        width: 124px;
        height: 124px;
        margin-right: 20px;
      }
    }
  }

  .course_list_wrap {
    width: 100%;

    &.scroll {
      overflow-x: scroll;
    }

    .course_list_content {
      width: calc(380px + 16px + 380px + 64px);
      padding: 30px 32px 8px;
      display: flex;
      flex-wrap: wrap;

      .course_item {
        width: 380px;
        height: 148px;
        border-radius: 8px;
        display: inline-block;
        border-radius: 10px;
        filter: drop-shadow(0 0 4px #E2E2E2);

        &:nth-child(2n) {
          margin-left: 16px;
        }

        &:nth-child(3),
        &:nth-child(4) {
          margin-top: 16px;
        }

        .inner {
          width: 100%;
          height: 100%;
          background: #fff;
          border-radius: 8px;
          padding: 24px;
          box-sizing: border-box;
          display: flex;
          justify-content: flex-start;
          align-items: center;

          >img {
            width: 100px;
            height: 100px;
            border-radius: 6px;
          }

          >div {
            width: calc(100% - 100px - 16px);
            height: 100px;
            margin-left: 16px;
            display: flex;
            flex-direction: column;
            justify-content: space-evenly;
            align-content: flex-start;

            .head {
              display: flex;
              justify-content: flex-start;
              align-items: center;

              .icon {
                height: 24px;
                line-height: 24px;
                background: #5B76FF;
                color: #FFF;
                font-size: 16px;
                white-space: nowrap;
                border-radius: 4px;
                flex: none;
                padding: 0 4px;
              }

              >.title {
                width: 180px;
                font-size: 28px;
                color: #333333;
                font-weight: 700;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
                margin-left: 4px;
                height: 30px;
                line-height: 30px;
              }
            }

            >.sub_title {
              font-size: 18px;
              color: #999999;
              font-weight: 700;
              overflow: hidden;
              text-overflow: ellipsis;
              white-space: nowrap;
            }
          }
        }
      }
    }
  }

}
</style>

<template>
  <div class="course_container" v-if="courseList.length && isZxjtqh">
    <header>
      <div>精品课程</div>
      <div class="course-more" @click="linkNiceCourse">
        <span>更多</span>
        <img src="@/assets/images/zxjt/gengduo.png" alt="" />
      </div>
      <img src="@/assets/images/zxjt/juxing.png" alt="" />
    </header>
    <div class="course-first-child" v-if="courseList.length == 1">
      <div class="course-wrap-box" v-for="(item, index) in courseList" :key="index" @click="handleEnterCourse(item)">
        <img class="left-img" :src="item.imgUrl + '?x-oss-process=image/resize,m_fixed,h_100,w_100'"
          alt="">
        <div class="wrap-middle-box">
          <div class="head">
            <span class="icon" v-if="(item.totalLessonNum && item.totalLessonNum > 1)">系列</span>
            <span class="title">{{ item.title }}</span>
          </div>
          <span class="sub_title">{{ item.subTitle }}</span>
        </div>
        <img class="right-img" src="@/assets/images/zxjtqh/course-home-icon.png" alt="">
      </div>
    </div>
    <div class="course_list_wrap" v-else :class="{ scroll: courseList.length > 1 }">
      <div class="course_list_content">
        <div class="course_item" v-for="(item, index) in courseList" :key="index" @click="handleEnterCourse(item)">
          <div class="inner">
            <img :src="item.imgUrl + '?x-oss-process=image/resize,m_fixed,h_100,w_100'" alt="">
            <div>
              <div class="head">
                <span class="icon" v-if="(item.totalLessonNum && item.totalLessonNum > 1)">系列</span>
                <span class="title">{{ item.title }}</span>
              </div>
              <span class="sub_title">{{ item.subTitle }}</span>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      isCourseContainer: false,
      isZxjtqh: this.$channel == 'zxjtqh' || this.$channel == 'neworg1',
      courseList: [], // 课程列表
    }
  },
  created() {
  },
  mounted() {
    // 获取精品课程
    this.getNiceCourse();
  },
  methods: {
    linkNiceCourse() {
      this.$router.push(`/${this.$channel}/niceCourse`)
    },
    // 获取精品课程
    getNiceCourse() {
      this.$http.get("/h5live/course/getNiceCourses", {
        params: {
          sort: 1,
          sortOrder: '',
          page: 1,
          pageSize: 4,
          homeShow: 1,
        }
      }).then(res => {
        if (res.data.code === "000000") {
          this.courseList = res.data.data;
        } else {
          return Promise.reject(res.data);
        }
      }).catch(err => {
        console.error(err);
      });
    },
    // 判断课程详情/课节
    handleEnterCourse(itemCourse) {
      const { courseId } = itemCourse;
      // 无课程ID拦截
      if (!courseId) {
        fun.toastMessage('未找到课程信息');
        return false;
      }
      this.$router.push(`/${this.$channel}/courseDetail?courseId=${courseId}`)
    }
  },
};
</script>
